package com.hbusa.cotroller.image; /**
 * @author XiaoXin
 * @date 2021/12/27 - 4:24
 */


import com.hbusa.dto.TbPicture;
import com.hbusa.service.ImageService;
import com.hbusa.service.impl.ImageServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/admin/doUpdate")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        String pictureId = (String) session.getAttribute("picture_id");
        ImageServiceImpl imageService = new ImageServiceImpl();
        System.out.println("pictureId:" + pictureId);
        String url = (String) req.getAttribute("url");
        System.out.println(url);
        TbPicture picture = new TbPicture();
        picture.setPictureUrl(url);
        boolean update = imageService.update(Integer.parseInt(pictureId), picture);
        if (update) {
            System.out.println("更新成功");
        } else {
            System.out.println("更新失败");
        }
        System.out.println("doUpdate执行了");
        session.removeAttribute("pictureId");
        resp.sendRedirect("doList");
    }
}
